﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreRay.Cameras
{
    public class PerspectiveCamera : Camera
    {
        public PerspectiveCamera(Vector3 position, Vector3 lookAt) : base(Matrix.LookAt(position, lookAt, new Vector3(0, 1, 0)))
        {
        }

        public PerspectiveCamera(Vector3 position, Vector3 lookAt, Vector3 upVector) : base(Matrix.LookAt(position, lookAt, upVector))
        {
        }

        public PerspectiveCamera(Matrix viewMatrix) : base(viewMatrix)
        {

        }

        public override Matrix GenerateProjectionMatrix(Film film)
        {
            return Matrix.PerspectiveFov(MathUtility.DegreesToRadians(37.9f), (float) film.Width / film.Height, 1.0f, 1000);
        }

        public override Ray GenerateRay(Sample sample)
        {
            Vector3 rasterPosition = new Vector3(sample.ImagePositionX, sample.ImagePositionY, 0.0f);

            Vector3 viewPosition = rasterPosition * this.RasterToView;

            Ray ray = new Ray(viewPosition, viewPosition.Normalize(), 1.0f, 100000.0f);

            ray = ray * this.ViewToWorld;

            return ray;
        }
    }
}
